#pragma once
#ifndef CHESS_H
#define CHESS_H
#include <fstream>

//dection为各个方向的递增值，从正上方开始顺时针转动,这里的棋盘为扩展后的棋盘
const int dection[8] = {-12,-11,1,13,12,11,-1,-13};
const int blackc = 1,whitec = 0,nochess = 2,out = 3,blackh = 4,whiteh = 5;
const int UNTOUCH = 30000;

class Chess{
public:
    int x,y,i;
    Chess(){}
    Chess(int posx,int posy):x(posx),y(posy){i = 12*y + x;}
    Chess(int pos[2]){
        x = pos[0];y = pos[1];
        i = 12* y +x;
    }
    Chess(int i){
       *this = i;
    }
    void setxy(int x,int y){
        this->x = x;
        this->y = y;
        i = 12* y +x;
    }
    bool operator== (Chess c){
        if (c.x == x && c.y == y)
            return true;
        else return false;
    }
    bool operator== (int i){
        if (this->i == i)
            return true;
        else return false;
    }
    bool operator!= (int i){
        if (this->i != i)
            return true;
        else return false;
    }
    void operator= (Chess c){
       x = c.x;
       y = c.y;
       i = c.i;
    }
    void operator= (int i){
        this->x = i%12;
        this->y = i/12;
        this->i = i;
    }
};


struct Movechess{
    Chess blackchess[4];
    Chess whitechess[4];
    Movechess(){};
    void operator=(const Movechess& movechess){
        for(int i = 0;i < 4;i++){
            this->blackchess[i] = movechess.blackchess[i];
            this->whitechess[i] = movechess.whitechess[i];
        }
    }
};


struct Score_struct{
    char king;
    char queen;
    Score_struct(char king,char queen): king(king),queen(queen){}
    Score_struct(){}
    bool is_valid(){
        if(king  >= 127) return false;
        else return true;
    }
    Score_struct set_invalid(){
        king = 127;
        return *this;
    }
};

struct Step{
    short oldchess;
    short chess;
    short hinder;
    Step(){}
    Step(short oldchess,short chess,short hinder):oldchess(oldchess),
        chess(chess),hinder(hinder){}
    Step(const Step&s) = default;
    void operator=(const Step &s){
        this->oldchess = s.oldchess;
        this->chess = s.chess;
        this->hinder = s.hinder;
    }
    void operator=(volatile const Step &s){
        this->oldchess = s.oldchess;
        this->chess = s.chess;
        this->hinder = s.hinder;
    }
};

//复制棋盘结构体
struct Cb_with_num{
    int chessborad[144];
    int chess_num;
    Movechess movechess;
    bool player;
    int blackcurrentmove = 0,blackcurrentset = 0,blackcurrenthinder = 0;
    int whitecurrentmove = 0,whitecurrentset = 0,whitecurrenthinder = 0;
    Cb_with_num(){}
    Cb_with_num(const Cb_with_num &cb){
        for (int i = 0;i < 144;i++ ) {
            chessborad[i] = cb.chessborad[i];
        }
        chess_num = cb.chess_num;
        movechess = cb.movechess;
        player = cb.player;
        blackcurrentmove = cb.blackcurrentmove,blackcurrentset = cb.blackcurrentset,blackcurrenthinder = cb.blackcurrenthinder;
        whitecurrentmove = cb.whitecurrentmove,whitecurrentset = cb.whitecurrentset,whitecurrenthinder = cb.whitecurrenthinder;
    }
};
#endif
